package com.openswimsoftware.orm.model.query.order;

import java.lang.reflect.Field;

import com.openswimsoftware.orm.ORM;

public class QueryOrderBy {
	
	private OrderDirection direction;
	private Field[] fields;
	
	public QueryOrderBy(OrderDirection direction, Field[] fields)
	{
		this.direction = direction;
		this.fields = fields;
	}
	
	public static String orderByString(QueryOrderBy orderBy)
	{
		if (orderBy == null)
		{
			return null;
		}
		
		String orderByString = "";
		
		boolean first = true;
		for (Field field: orderBy.fields)
		{
			if (first)
			{
				first = false;
			}
			else
			{
				orderByString += ", ";
			}
			
			orderByString += ORM.fieldName(field);
		}
		
		orderByString += " " + orderBy.direction.toString();
		
		return orderByString;
	}
	
}
